#include "exppass.h"
#include "ui_exppass.h"

ExpPass::ExpPass(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ExpPass)
{
    ui->setupUi(this);
    bdf = BllDataFlow::getInstance();

    //Signals and Slots
    connect(bdf, &BllDataFlow::updateExpPassInfoSignal, this, &ExpPass::updateExpPassInfo);
    connect(bdf, &BllDataFlow::retranslateUiSignal, this, &ExpPass::retranslateUiSlot);

    setAttribute(Qt::WA_TranslucentBackground, true);
    QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
    shadow->setColor(QColor(0,0,0,150));
    shadow->setOffset(1, 1);
    shadow->setBlurRadius(16);
    ui->widget->setGraphicsEffect(shadow);
    this->setWindowFlags(this->windowFlags() | Qt::SubWindow);
}

ExpPass::~ExpPass()
{
    delete ui;
}

void ExpPass::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.fillRect(this->rect(), QColor(255, 255, 255, 0));
}

void ExpPass::showEvent(QShowEvent *)
{
    this->activateWindow();
}


void ExpPass::on_btnOK_clicked()
{
    this->hide();
    bdf->changeExperimentPageIndex(0);
}

void ExpPass::updateExpPassInfo(ExperimentInfo expInfo)
{
    ui->lblExpStartDatetime->setText(expInfo.datetimeExpStart);
    ui->lblExpDuration->setText(expInfo.duration);
    bdf->insertExpInfo(expInfo);
}

void ExpPass::retranslateUiSlot()
{
    ui->retranslateUi(this);
}
